<template>
  <div class="hello">
  </div>
</template>

<script>
export default {
    name:"author",
  data () {
    return {

    }
  },
  mounted(){
      const that = this;
      that.login();
      //存用户进来的路径,登陆以后跳转用
      // if(that.$store.state.toUrl !== '/author' && that.$store.state.toUrl !== "/binzerone"){
      //     that.$cookies.set('toUrl',that.$store.state.toUrl);
      // }
      // if (/MicroMessenger/.test(window.navigator.userAgent)) {
      //     console.log('微信客户端');
      //     //后台是否有用户信息
      //     var navigator_url = "wechat_fang";
      //     that.$store.state.is_navigator = "wechat_user";
      //     that.login(navigator_url);
      // }
      // else if (/AlipayClient/.test(window.navigator.userAgent)) {
      //     let txt = "请使用微信或浏览器进入!";
      //     that.showToastTxtOnly(txt);
      //     console.log('支付宝客户端');
      //       //授权链接常量
      //       // var navigator_url = "ali_fang";
      //       // //判断从哪里进来的
      //       // this.$store.state.is_navigator = "ali_user";
      //       // this.login(navigator_url);
      // }
      // else {
      //     console.log('其它浏览器');
      //     let txt = "请使用微信浏览器进入!";
      //     that.showToastTxtOnly(txt);
      // }
    },
    methods:{
        // login(navigator_url){
        //     let that = this;
        //     let _token01 = that.$cookies.get('_token01');
        //     console.log(_token01,"_token01autho");
        //     let _user_mark = that.$cookies.get('_user_mark');
        //
        //     let host  = that.$store.state.host;
        //     let static_host  = that.$store.state.static_host;
        //     let toUrl  = "/shop"+that.$store.state.toUrl;
        //     let Base64 = require('js-base64').Base64;
        //     static_host = Base64.encode(static_host + toUrl);
        //     //防止带People_id进来因为跳转而丢失People_id
        //     let cookiespeople_id = that.$store.state.binPeople_id;
        //     if(cookiespeople_id){
        //         that.$cookies.set("binPeople_id",cookiespeople_id,"2h");
        //     }
        //     if(_token01 === null){
        //             //用户是否绑定了手机
        //           if(_user_mark === null){
        //               window.location.href = host+"/fang/auth/"+navigator_url+"?redirect_uri="+static_host;
        //           }
        //           else{
        //               // // isRegister不需要注册的页面
        //               // let isRegister = that.$store.state.isRegister;
        //               // console.log(isRegister,"isRegister");
        //               // if (isRegister == that.$store.state.no_login.index ||
        //               //     isRegister == that.$store.state.no_login.shouye ||
        //               //     isRegister == that.$store.state.no_login.selectadress ||
        //               //     isRegister == that.$store.state.no_login.shopdetails ||
        //               //     isRegister == that.$store.state.no_login.successpm ||
        //               //     isRegister == that.$store.state.no_login.dynamic
        //               //     ) {
        //               //         //本应该跳转index,但是由于没有用户信息进入中间页面author,再跳转到index就获取不到params,所以只能跳转author
        //               //         //在author中判断
        //               //         if(that.$route.params.latitude && that.$route.params.longitude){
        //               //             that.$router.replace({ name: 'index',
        //               //             params: { latitude: that.$route.params.latitude,
        //               //                 longitude:that.$route.params.longitude}
        //               //             })
        //               //         }else{
        //               //             that.back();
        //               //         }
        //               //
        //               // }else{
        //                   that.$router.replace("/binzerone");
        //               // }
        //           }
        //     }else{
        //         that.$store.state._token01 = _token01;
        //         that.$axios.post("/fang/personal/user_info",that.$qs.stringify({
        //                   access_token:_token01
        //             }))
        //             .then(function (response) {
        //                   let res = response.data;
        //                   if(res.status == 1){
        //                       // 保存用户登录状态($cookies)
        //                       if(res.data.item.nickname && res.data.item.headimgurl)
        //                       {
        //                           that.$cookies.set("nickname",res.data.item.nickname,"2h");
        //                           that.$cookies.set("headimgurl",res.data.item.headimgurl,"2h");
        //                           // 保存用户登录状态(Vuex)
        //                           that.$store.commit('setUser',{
        //                               nickname : res.data.item.nickname,
        //                               headimgurl : res.data.item.headimgurl
        //                           });
        //                       }
        //                       // console.log(res.data.people_info,"res.data.people_info")
        //                       //绑粉用的分享参数
        //                       if(res.data.people_info){
        //                           console.log(res.data.people_info.id,"res.data.people_info.id")
        //                           let people_info = res.data.people_info;
        //                           that.$store.state.people_info = people_info;
        //                       }
        //                       //绑定粉丝
        //                       let binPeople_id = that.$cookies.get('binPeople_id');
        //                       if(binPeople_id){
        //                           that.$axios.post("/fang/personal/bind_people",that.$qs.stringify({
        //                                     access_token:_token01,
        //                                     people_id:binPeople_id
        //                               }))
        //                               .then(function (response) {
        //                                   console.log(response,"binPeople_id")
        //                                   that.$cookies.remove('binPeople_id');
        //                               })
        //                               .catch(function (error) {
        //                                 console.log(error);
        //                           });
        //                       }
        //                       that.back();
        //                   }else if(res.status == -1){
        //                       that.$cookies.remove('_token01','/','.01nnt.com');
        //                       that.$cookies.remove("_user_mark",'/','.01nnt.com');
        //                       window.location.href = host+"/fang/auth/"+navigator_url+"?redirect_uri="+static_host;
        //                   }
        //                   else{
        //                       that.back();
        //                   }
        //             })
        //             .catch(function (error) {
        //               console.log(error);
        //                let title = "出错了";
        //               that.showAlert(error,title);
        //         });
        //     }
        // },
        login(){
            let that = this;
            let _token01 = that.$cookies.get('_token01');
            console.log(_token01,"_token01autho");
            // let _user_mark = that.$cookies.get('_user_mark');

            let host  = that.$store.state.host;
            let static_host  = that.$store.state.static_host;
            let toUrl  = "/shop"+that.$store.state.toUrl;
            let Base64 = require('js-base64').Base64;
            static_host = Base64.encode(static_host + toUrl);

            that.$store.state._token01 = _token01;
            that.$axios.post("/fang/personal/user_info",that.$qs.stringify({
                      access_token:_token01
                }))
                .then(function (response) {
                      let res = response.data;
                      if(res.status == 1){
                          // 保存用户登录状态($cookies)
                          if(res.data.item.nickname && res.data.item.headimgurl)
                          {
                              that.$cookies.set("nickname",res.data.item.nickname,"2h");
                              that.$cookies.set("headimgurl",res.data.item.headimgurl,"2h");
                              // 保存用户登录状态(Vuex)
                              that.$store.commit('setUser',{
                                  nickname : res.data.item.nickname,
                                  headimgurl : res.data.item.headimgurl
                              });
                          }
                          //绑粉用的分享参数(在分享的时候用)
                          if(res.data.people_info){
                              console.log(res.data.people_info.id,"res.data.people_info.id")
                              let people_info = res.data.people_info;
                              that.$store.state.people_info = people_info;
                          }

                          that.back();
                      }else if(res.status == -1){
                          that.$cookies.remove('_token01','/','.01nnt.com');
                          that.$cookies.remove("_user_mark",'/','.01nnt.com');
                          window.location.href = host+"/fang/auth/wechat_fang?redirect_uri="+static_host;
                      }
                      else{
                          that.back();
                      }
                })
                .catch(function (error) {
                  console.log(error);
                   let title = "出错了";
                  that.showAlert(error,title);
            });
        },
        back:function(){
            let that = this;
            //跳转用户进来的页面
            if(!that.$store.state.toUrl || that.$store.state.toUrl == "/binzerone" || that.$store.state.toUrl=="/author"){
                that.$router.replace("/");
            }else{
                that.$router.replace(that.$store.state.toUrl);
            }
        },
        showAlert(error,title) {
          this.$createDialog({
            type: 'alert',
            title: title,
            content: error+'请检查网络,重新进入',
            icon: 'cubeic-alert'
          }).show()
      },
      showToastTxtOnly(txt) {
          this.toast = this.$createToast({
            txt: txt,
            type: 'txt'
          })
          this.toast.show()
        }
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
